package org.example.service.client;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.example.HelloServiceGrpc;
import org.example.helloProto;

/**
 * @Author : 叶荻风
 * @create : 2024/6/20 11:44
 */
public class GrpcClient {
    public static void main(String[] args) {
        //1.创建通信的管道
        ManagedChannel managedChannel = ManagedChannelBuilder.forAddress("localhost",9000).usePlaintext().build();
        //2.获取代理对象stub
        HelloServiceGrpc.HelloServiceBlockingStub stub = HelloServiceGrpc.newBlockingStub(managedChannel);
        //客户端监控onComplete
        //3.完成RPC调用
        //3.2准备参数
        helloProto.HelloRequest request = helloProto.HelloRequest.newBuilder().setUsername("difeng").build();
        helloProto.HelloResponse response = stub.hello(request);
        System.out.println(response.getUsername());

        //list通过addName
        helloProto.HelloRequest1 request1 = helloProto.HelloRequest1.newBuilder().addName("a").addName("b").build();
        helloProto.HelloResponse1 response1 = stub.hello1(request1);
        System.out.println("任务处理完毕1:"+response1.getResultList());
        managedChannel.shutdown();
    }
}
